package day_2022_9_to_12.Day;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2022/11/15 11:44
 **/
public class Day71_1_Num1710_MaximumUnits {
    class Solution {
        public int maximumUnits(int[][] boxTypes, int truckSize) {
            int n = boxTypes.length, ans = 0;
            Arrays.sort(boxTypes, (a, b) -> (b[1] - a[1]));
            for(int i = 0, boxs = 0; i < n && boxs < truckSize; ++i){
                int a = boxTypes[i][0];
                int b = boxTypes[i][1];
                int curBoxs = Math.min(a, truckSize - boxs);
                ans += curBoxs * b;
                boxs += curBoxs;
            }
            return ans;
        }
    }
}